#!/usr/bin/perl
use strict;
use LWP::Simple; 

if (! $ARGV[0]) { Usage(); }
our @Paths = ("/", "ftp", "protected", "_private", "_siteadmin", "bak", "backup", "blog", "wiki", "forums", "site", "archive", "storage", "restore", "save", "working", "content", "old", "tmp", "temp", "www");
our @Archives = ("tar", "tar.gz", "tgz", "zip", "rar", "7z", "bak", "old"); 
our @ConfigFiles = ("web.config", "wp-config.php", "config.php", "configuration.php", "LocalSettings.php", "settings.php", "mt-config.cgi", "login.php");
our @BackupExt = ("~", ".swp", ".swo", "#", ".save", ".bak", ".temp", ".tmp", ".\$");
our $UserAgent = "Mozilla/5.0";
our $URL = $ARGV[0];
our ($ThisRunPath,$Proto,$Domain,$SubDir,$CheckType);

if ($URL =~ /(https?:\/\/)?([^\/]+)\/?(.+)?\/?/gi) { 
	 $Proto = $1 || "http://";
	 $Domain = $2; 
	 $SubDir = $3;
	 $SubDir =~ s/\/$//g;
	}

## Debug
#print "Proto: $Proto\nDomain: $Domain\nSubDir: $SubDir\n"; 
#exit 0;
## Debug

print "\n\nNicholas' Website Archive Brute Force Utility (WABFU) 2011\n";
print "-"x67;
print "\nDo you want to run Archive Checks (a), Swap File checks (s) or Both (B)? ";
	chomp ($CheckType = <STDIN>);
		if (! $CheckType) { $CheckType = "b"; }

print "\n[=] DOMAIN: $Domain";
if ($SubDir) { print "\tDIRECTORY: $SubDir\n"; }
else { print "\n"; }
foreach $ThisRunPath (@Paths) { 
	print "[+] Trying $ThisRunPath:";

if ($CheckType =~ /a/i || $CheckType =~ /b/i) {
	foreach (@Archives) {
		print " ($_)";
		my $StoreFile = "$Domain-$SubDir-$ThisRunPath.$_";
			$StoreFile =~ s/\//_/g;
		getstore("$Proto$Domain/$SubDir/$ThisRunPath/$Domain.$_", "$StoreFile"); 
		if (-e "$StoreFile") {
			my $CheckType = `file $StoreFile`; 
			if ($CheckType =~ /(HTML|ASCII)/gi) { unlink ("$StoreFile"); }
		}
	 	if (-e "$StoreFile")  { 
			print ("\n[!] Archive Found and stored!\n");
			print ("[+] Continuing $ThisRunPath:"); 
		}
	}	
	print "\n";
}

if ($CheckType =~ /s/i || $CheckType =~ /b/i) {
	foreach (@ConfigFiles) {
		print "\t$_: ";
			my $Filename=$_;
			foreach (@BackupExt) {
				print "($_)";
		my $StoreFile = "$Domain-$SubDir-$ThisRunPath.$Filename$_";
			$StoreFile =~ s/\//_/g;
		getstore("$Proto$Domain/$SubDir/$ThisRunPath/$Domain.$Filename$_", "$StoreFile"); 
		if (-z "$StoreFile") {
			unlink ("$StoreFile");
		}
	 	if (-e "$StoreFile")  { 
			print ("\n[!] Backup Found and stored!\n");
			print ("[+] Continuing $ThisRunPath:"); 
		}
	}	
	print "\n";
}

}
}
print "[=] Finished.\n";

sub Usage {
	die ("Usage: $0 [DOMAIN]\n");
}
